package models

import (
	"gorm.io/gorm"
	"server/global"
)

var (
	db       = global.MysqlDB
	EsClient = global.EsClient
)

func init() {
	err := db.AutoMigrate(&Userss{}, &Fruit10{})
	if err != nil {
		panic(err)
	}
}

type Userss struct {
	gorm.Model
	Username string
	Password string
}
type Fruit10 struct {
	gorm.Model
	Name      string `json:"name"`
	Title     string `json:"title"`
	Type      string `json:"type"`
	Content   string `json:"content"`
	Inventory int    `json:"inventory"`
}

func GetUserInfo(userss Userss) (Userss, error) {
	var Users Userss
	res := db.Where(userss).First(&Users)
	return Users, res.Error
}
func CreateFruit(fruit10 Fruit10) (Fruit10, error) {
	res := db.Create(&fruit10)
	return fruit10, res.Error
}
